#include "common_includes.h"
#include <map>
#include "ftp_user.h"
#include "ftp_group.h"


#include <sys/types.h>
#include <pwd.h>
#include <grp.h>

#ifndef FTPUSERSCONFIGURATIONREADER_H
#define FTPUSERSCONFIGURATIONREADER_H

AUTH_NS_START

/**
 * @class FtpUsersConfigurationReader
 * @file ftp_users_configuration_reader.h
 * @brief Handles Population of User and Group List with the Linux Users and Groups.
 */
class FtpUsersConfigurationReader {

private:
	/**
	 * @brief Declaration to prevent copy ctor
	 * @param rhs
	 */
	FtpUsersConfigurationReader(const FtpUsersConfigurationReader& rhs);

	/**
	 * @brief Declartion to prevent = operator
	 * @param rhs
	 */
	FtpUsersConfigurationReader& operator=(const FtpUsersConfigurationReader& rhs);

public:
	typedef std::map<uid_t,FtpUser*> UserListType;
	typedef std::map<gid_t,FtpGroup*> GroupListType;

	UserListType m_UserList;
	GroupListType m_GroupList;

	FtpUser* InsertUserToList(const passwd* user);
	FtpGroup* InsertGroupToList(const group* grp);

public:
	/**
	 * @brief Creates an instances of FtpUsersConfigurationReader
	 */
	FtpUsersConfigurationReader();

	virtual ~FtpUsersConfigurationReader();
	
	/**
	 * @brief Looks up the user by uid
	 * @param userId The Uid of the user
	 * @return The User if the userid is found, NULL otherwise.
	 */
	FtpUser* GetUserById(uid_t userId) const;
	
	/**
	 * @brief Looks up a group by the Group Id
	 * @param groupId The GId
	 * @return The group if found NULL otherwise
	 */
	FtpGroup* GetGroupById(gid_t groupId) const;

	/**
	 * @brief Indicates whether the reader is initialized
	 * @return true if Initialized, false otherwise
	 */
	bool IsInitialized() const {
		return this->m_bIsInitialized;
	}

	/**
	 * @brief Initializes the reader.
	 */
	void Initialize();

private:

	bool m_bIsInitialized;


};

AUTH_NS_END
#endif // FTPUSERSCONFIGURATIONREADER_H
